import {SysUser} from "@/api/system/user";

const TOKEN_KEY = 'auth_token';
const USER_KEY = 'userInfo';
interface UserInfoProps {
    nickName: string;

}

// 获取 token
export const getToken = (): string | null => {
    return localStorage.getItem(TOKEN_KEY);
};

// 设置 token
export const setToken = (token: string): void => {
    localStorage.setItem(TOKEN_KEY, token);
};

// 清除 token
export const clearToken = (): void => {
    localStorage.removeItem(TOKEN_KEY);
};

// 检查是否登录
export const isAuthenticated = (): boolean => {
    return !!getToken();
};

// 获取当前用户
export const getUserInfo = () => {
    const userInfo: any = localStorage.getItem(USER_KEY)
    return userInfo ? JSON.parse(userInfo) : {};
};

// 设置用户
export const setUserInfo = (userData: SysUser) => {
    localStorage.setItem(USER_KEY, JSON.stringify(userData));
};

// 清除用户
export const clearUserInfo = () => {
    localStorage.removeItem(USER_KEY);
};
